<?php

require_once('../../config/maptrick.conf.php');
require_once(SITE_ROOT . 'lib/PHT.php');
require_once(SITE_ROOT . 'class/bean/League.class.php');
require_once(SITE_ROOT . 'class/db/DBLeague.class.php');

try {
	$dbleague = new DBLeague();
	$leagues = $dbleague->getLeaguesByLevel(1);
	
	$HT = new CHPPConnection(VERSION, CHPPID, CHPPKEY, SITE_ROOT . 'tmp/hattrick/');
	if ($HT->connectUser(HTUSER, HTSECCODE)) {
		foreach ($leagues as $league) {
			$league->setName($HT->getLeague($league->getLeagueID())->getLeagueLevelName());
		}
		$HT->disconnect();
	}
	else echo "Login error !";
	$dbleague->saveLeagues($leagues);
}
catch (Exception $e) {
	echo $e->getMessage();
	$HT->disconnect();
}

?>